package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(11);not null"`
	Password string `gorm:"type:varchar(32);not null"`
	NickName string `gorm:"type:varchar(20);not null"`
	Address  string `gorm:"type:varchar(50);not null"`
}

func (u *User) FirstOrCreateUser(db *gorm.DB, account string) error {
	return db.Debug().Where("account=?", account).FirstOrCreate(u).Error
}

func (u *User) FindUserByUserId(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

func (u *User) UpdateUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FindUser(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(u).Error
}
